package net.chasing.androidbaseconfig.widget.view_pager;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;

import net.chasing.androidbaseconfig.R;
import net.chasing.androidbaseconfig.adapter.recycleradaper.RecyclerQuickAdapter;
import net.chasing.androidbaseconfig.adapter.recycleradaper.RecyclerViewHelper;

public class ViewPagerIndicatorAdapter extends RecyclerQuickAdapter<String> {
    private int selectPosition;
    private int size;
    private GradientDrawable selectDrawable, unSelectDrawable;

    ViewPagerIndicatorAdapter(Context context) {
        super(context, R.layout.item_indicator);

        selectDrawable = new GradientDrawable();//创建drawable
        selectDrawable.setColor(Color.parseColor("#bfbfbf"));
        selectDrawable.setCornerRadius(90);

        unSelectDrawable = new GradientDrawable();//创建drawable
        unSelectDrawable.setColor(Color.parseColor("#ececec"));
        unSelectDrawable.setCornerRadius(90);
    }

    public void setSelectPosition(int selectPosition) {
        int prePosition = this.selectPosition;
        this.selectPosition = selectPosition;
        notifyItemChanged(prePosition);
        notifyItemChanged(this.selectPosition);
    }

    public void setSize(int size) {
        this.size = size;
    }

    void setSelectColor(int color) {
        selectDrawable = new GradientDrawable();
        selectDrawable.setColor(color);
        selectDrawable.setCornerRadius(90);
    }

    void setUnSelectColor(int color) {
        unSelectDrawable = new GradientDrawable();
        unSelectDrawable.setColor(color);
        unSelectDrawable.setCornerRadius(90);
    }

    @Override
    protected void convert(int viewType, RecyclerViewHelper helper, String s) {
        helper.setBackgroundDrawable(R.id.indicator, helper.position == selectPosition ? selectDrawable : unSelectDrawable);
        if (size > 0)
            helper.setViewWidth(R.id.indicator, size)
                    .setViewHeight(R.id.indicator, size);
    }
}
